Skip to content

Number systems

Alt text

Alt text

Understand binary

  • Any form of data needs to be converted to binary to be processed by a computer.
  • The basic building block in all computers is the binary number system.

Switch

Switch ON is 1 and OFF is 0. Alt text

Alt text

Digit weight

  • Every one of us is used to the decimal or denary (base 10) number system. This uses the digits 0 to 9 which are placed in ‘weighted’ columns.
100001000100101
104103102101100
31421
  • Example: 3x10000 + 1x1000 + 4x100 + 2x10 + 1x1 = 31421

Binary to denary

  • Except for denary, we use binary(base 2) and hexadecimal(base 16) number system in the computer.
Denary value0123456789101112131415
Binary value0000000100100011010001010110011110001001101010111100110111101111
Hexadecimal value0123456789ABCDEF
  • The binary system uses 1s and 0s only which gives these corresponding weightings.
  • We can convert binary number to denary according to digit weightings.
1286432168421
2726252423222120
11101110
  • Example: 1110 11102 = 128 + 64 + 32 + 8 + 4 + 2 = 23810

Hexadecimal to denary

  • The hexadecimal system is very closely related to the binary system.
  • Hexadecimal is a base 16 system.
  • Because it is a system based on 16 different digits, the numbers 0 to 9 and the letters A to F are used to represent hexadecimal digits.
  • A = 10, B = 11, C = 12, D = 13, E = 14 and F = 15.
  • We can convert hexadecimal number to denary according to digit weightings.
655364096256161
164163162161160
01123

Example: 0112316 = 1x4096 + 1x256 + 2x16 + 3x1 = 438710

Use of the hexadecimal system

  • Areas within computer science that hexadecimal is used should be identified:

    • Error codes
    • MAC addresses
    • IPv6 addresses
    • HTML colour codes
  • Hexadecimal is easier for humans to understand than binary, as it is a shorter representation of the binary.

  • When the memory contents are output to a printer or monitor, this is known as a memory dump.

Alt text

Denary to binary

  • Converting from denary to binary is slightly more complex.
  • This method involves successive division by 2 until the result is 0; the remainders are then written from bottom to top to give the binary value.
DividerResultRemainderProcess
2107
2531107 ➗ 2 = 53 ……1
226153 ➗ 2 = 26 ……1
213026 ➗ 2 = 13 ……0
26113 ➗ 2 = 6 ……1
2306 ➗ 2 = 3 ……0
2113 ➗ 2 = 1 ……1
011 ➗ 2 = 0 ……1
  • Example: 10710 = 110 10112

Denary to hexadecimal

  • Converting from denary to hexadecimal is slightly similar with denary to binary.
  • This method involves successive division by 16; the remainders are then written from bottom to top to give the hexadecimal value.
DividerResultRemainderProcess
162004
1612542004 ➗ 16 = 125 ……4
16713(D)125 ➗ 16 = 7 ……13(D)
16077 ➗ 16 = 0 ……7
  • Example: 200410 = 7D416

Binary to hexadecimal

  • Since 16 = 24, four binary digits are equivalent to each hexadecimal digit.
Binary value0000000100100011010001010110011110001001101010111100110111101111
Hexadecimal value0123456789ABCDEF
Denary value0123456789101112131415
  • Example: 11111000012 = 0011 1110 00012 = 3E116

Hexadecimal to binary

  • Since 16 = 24, one hexadecimal digit are equivalent to four binary digits.

  • Example: 45A16 = 0100 0101 10102

Binary addition

bianry addtion

  • 0 + 0 = 0
  • 1 + 0 = 1 (sum 1 and carry 0)
  • 1 + 1 = 10 (sum 0 and carry 1 )
  • 1 + 1 + (carry 1) = 11= sum 1 and carry 1
  • Add 0 0 1 0 0 1 0 1 (37 in denary) and 0 0 1 1 1 0 1 0 (58 in denary).
-1286432168421
3700100101
+
5800111010
=
Carry01000000
Sum01011111
  • The sum is 0101 1111, which is 95 in denary.

Overflow error

  • Add 0 1 0 1 0 0 1 0 (82 in denary) and 0 1 0 0 0 1 0 1 (69 in denary).
-1286432168421
8201010010
+
6901000101
=
Carry10000000
Sum10010111
  • The sum is 1001 0111, which is -105 (Incorrect)

Overflow error

  • The expected answer for 82 + 69 is 151, which is out of range for the 8 bits register (-128~127), this is known as an overflow error.

Logical shifts

  • The positive binary integer is multiplied or divided according to the shift performed.
  • Bits shifted from the end of the register are lost and zeros are shifted in at the opposite end of the register.
  • The most significant bit(s) or least significant bit(s) are lost.

Alt text